package cn.virens.cmpt.rabbit;

import cn.virens.cmpt.rabbit.packet.RabbitPacket;

public abstract class RabbitConsumerHandler<T extends RabbitPacket> {

	public boolean isSupport(String cmd) {
		return false;
	}

	public void doHandler(RabbitConsumerProps prop, byte[] bytes) throws Exception {
		if (bytes != null) doHandler0(prop, createRabbitPacket(bytes));
	}

	public void doHandler0(RabbitConsumerProps prop, T packet) throws Exception {
	}

	@SuppressWarnings("unchecked")
	protected void doHandler0(RabbitPacket packet) throws Exception {
		this.doHandler0(null, (T) packet);
	}

	protected T createRabbitPacket(byte[] bytes) {
		return null;
	}

}
